<template>
  <div id="bg">
<!--    动态粒子属性   -->
    <vue-particles
      color="#fff"
      :particleOpacity="0.7"
      :particlesNumber="60"
      shapeType="circle"
      :particleSize="4"
      linesColor="#fff"
      :linesWidth="1"
      :lineLinked="true"
      :lineOpacity="0.3"
      :linesDistance="180"
      :moveSpeed="2"
      :hoverEffect="true"
      hoverMode="repulse"
      :clickEffect="true"
      clickMode="push">
    </vue-particles>
  <div class="">
  <div class="login" >
<!--    登录logo展示   -->
    <div id="ll">
      <img src="../assets/images/loginLogo.png">
    </div>
    <el-form :model="form" :rules="rules" ref="ruleForm">
      <el-form-item prop="userId">
        <el-input placeholder="请输入账号" class="te" v-model="form.userId" clearable prefix-icon="el-icon-s-custom" style="color: white"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input placeholder="请输入密码" class="te" v-model="form.password" clearable show-password prefix-icon="el-icon-lock"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"   round  @click="login" :loading="loading">{{title}}</el-button>
      </el-form-item>
    </el-form>
  </div>
  </div>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      form: {
        userId: '',
        password: ''
      },
      //控制登录动画
      loading: false,
      title: '登录',
      //前端控制登入规则
      rules:{
        userId:[{ required: true, message: '请输入账号', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
      }
    }
  },
  methods: {
    //登录方法
    login() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          //开启登录动画
          this.loading = true;
          this.title = '登录中...'
          //请求
          this.$axios({
            url: 'sys/user/login',
            method: 'post',
            data: this.form
          }).then(res => {
            //请求成功
            if (res.data.success) {
              this.$store.commit('token', res.data.object.token)
              this.$store.commit('loginUserName', res.data.object.loginUserName)
              this.$store.commit('authIndexList', res.data.object.authIndexList)
              this.$store.commit('breadcrumbTitle','')
              this.$store.commit('breadcrumbIndex', '')
              this.$router.push('Home')
            } else {
              //关闭登录动画
              this.loading = false;
              this.title = '登录'
              this.$message(res.data.message);
            }
          }).catch(err => {
            //错误    关闭登录动画
            this.loading = false;
            this.title = '登录'
            console.info(err)
            this.$message.error(err.message);
          })
        }
      });
    }
  }
}
</script>

<style>
/*输入框内字体颜色、圆边、边框颜色、透明度*/
.el-input__inner{
  color: white;
  border-radius: 100px;
  border: 2px solid #4e82a1;
  background-color: rgba(255,255,255,0.247);
}
</style>

<style scoped>
/*粒子背景样式*/
#particles-js {
  width: 100%;
  height: calc(100% - 100px);
  position: absolute;
}
/*登录框位置*/
.login{
  width: 350px;
  height: 150px;
  margin: 15% auto;
  text-align: center;
}
/*按钮宽度和颜色透明度*/
.el-button{
  width: 100%;
  background-color: rgba(255,255,255,0.247);
}
/*登录页面背景图*/
#bg{
  position: fixed;
  width: 100%;
  height: 100%;
  margin: -8px;
  background-image: url("../assets/images/loginBg1.jpg");
  background-size: 100% 100%;
  background-repeat: no-repeat;
}
/*登录文字logo位置*/
#ll{
  margin-left: 0;
}
</style>
